<?php
        require_once('../inc/users.php');
        require_once('../inc/purchase.php');
        $results = getPurchases();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Database Access: Puchases</title>
        <link type="text/css" rel="stylesheet" href="../inc/bootstrap.css" />
        <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css" />
    </head>
   
    <body>
    	<div class="container">
    	<? include('../inc/header.php'); ?>
    	<? include('../inc/nav.php'); ?>
    	<div id="contents">
    	
    	 <? if(isset($_GET['inserted'])): ?>
                        <div class="alert alert-success">
                        <button class="close">×</button>
                        Record inserted succesfuly.
                    </div>
                <? endif; ?>
                
		<form method="post" action="edit.php">
         <table class="table table-striped table-bordered table-condensed table-hover">
         		<thead>
                <tr>
                <th>First Name</th><th>Last Name</th><th>Purchase Date</th><th>Total</th><th>Credit Card</th><th>Actions</th>
            </tr>
            </thead>
            
            <tbody>
            <? while($rs = $results->fetch_assoc()):
            	$rs1 = GetUser($rs['user_ID']);?>
                <tr class="<?=$rs['purchase_ID'] == $_GET['inserted'] ? 'info' : ''?>">
                    <td><?=$rs1['firstName']?></td>
                    <td><?=$rs1['secondName']?></td>
                    <td><?=$rs['purchaseDate']?></td>
                    <td><?=$rs['total']?></td>
                    <td><?=$rs['creditCard']?></td>
                    <td>
                    	<!--<a href="details.php?id=<?=$rs['user_ID']?>&purchase_ID=<?=$rs['purchase_ID']?>">Details</a>-->
						<a href="edit.php?id=<?=$rs['user_ID']?>&purchase_ID=<?=$rs['purchase_ID']?>" class="edit-link">Edit</a>   
                    	<a href="delete.php?id=<?=$rs['user_ID']?>&purchase_ID=<?=$rs['purchase_ID']?>" class="delete-link">Delete</a>
                    	<a href="edit.php?id=<?=$rs['user_ID']?>" class="edit-link">Add</a>
                    </td>
                  </tr>
              <? endwhile; ?>
                	 

			<?	$results1 = noPuchase();               
				while($rs3 = $results1->fetch_assoc()):?> 
				  <tr>
                    <td><?=$rs3['firstName']?></td>
                    <td><?=$rs3['secondName']?></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td>
                      	<a href="edit.php?id=<?=$rs3['user_ID']?>" class="edit-link">Add</a>
                    </td>
                </tr>
            <? endwhile; ?>
            </tbody>
        </table>
        </form>
        </div>
       </div>
       
			<div class="modal hide fade">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h1>Delete Purchase</h1>
                </div>
                <div class="modal-body"></div>
            </div>
            
            <script type="application/javascript" src="../inc/jquery.timepicker.js"></script>
       
		<? include("../inc/jQueryStart.php")?>;
      
    </body>
</html>